<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- <script>
      var arr = [3, 6, 4, 5, 2, 1, 8, 9, 7, 0];
      var temp;

      for (var j = 0; j < arr.length-1; j++) {

        /* 第0次循环 01比干到 89比 */
        /* 第1次循环 01比干到 78比 */
        /* 第j次循环 01比干到 arr.length - (j+2)比arr.length - (j+1)比 */
        for (var i = 0; i < arr.length - (j+1); i++) {
          // i与i+1进行两两比较，大的往后串
          if (arr[i] > arr[i + 1]) {
            temp = arr[i];
            arr[i] = arr[i + 1];
            arr[i + 1] = temp;
          }
        }
        console.log(arr);

      }
    </script> -->

    <!-- <script>
      var arr = [3, 6, 4, 5, 2, 1, 8, 9, 7, 0];
      var temp;

      /* 01~89 */
      for (var i = 0; i <= arr.length - 2; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~78 */
      for (var i = 0; i <= arr.length - 3; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~67 */
      for (var i = 0; i <= arr.length - 4; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~56 */
      for (var i = 0; i <= arr.length - 5; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~45 */
      for (var i = 0; i <= arr.length - 6; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~34 */
      for (var i = 0; i <= arr.length - 7; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~23 */
      for (var i = 0; i <= arr.length - 8; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~12 */
      for (var i = 0; i <= arr.length - 9; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

      /* 01~01 */
      for (var i = 0; i <= arr.length - 10; i++) {
        if (arr[i] > arr[i + 1]) {
          temp = arr[i];
          arr[i] = arr[i + 1];
          arr[i + 1] = temp;
        }
      }
      console.log(arr);

    </script> -->

    <script>
      var arr = [3, 6, 4, 5, 2, 1, 8, 9, 7, 0];
      var temp;

      for (var j = 1; j < arr.length; j++) {

        for (var i = 0; i < arr.length - j; i++) {
          if (arr[i] > arr[i + 1]) {
            temp = arr[i];
            arr[i] = arr[i + 1];
            arr[i + 1] = temp;
          }
        }
        console.log(arr);
        
      }
    </script>
  </body>
</html>
